/*
 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#ifndef __DFS_DIR2_PRIV_H__
#define __DFS_DIR2_PRIV_H__

struct dir_context;

/* dfs_dir2.c */
extern int dfs_dir_ino_validate(struct dfs_mount *mp, dfs_ino_t ino);
extern int dfs_dir2_grow_inode(struct dfs_da_args *args, int space,
				dfs_dir2_db_t *dbp);
extern int dfs_dir_cilookup_result(struct dfs_da_args *args,
				const unsigned char *name, int len);

#define S_SHIFT 12
extern const unsigned char dfs_mode_to_ftype[];

extern unsigned char dfs_dir3_get_dtype(struct dfs_mount *mp,
					__uint8_t filetype);


/* dfs_dir2_block.c */
extern int dfs_dir3_block_read(struct dfs_trans *tp, struct dfs_inode *dp,
			       struct dfs_buf **bpp);
extern int dfs_dir2_block_addname(struct dfs_da_args *args);
extern int dfs_dir2_block_lookup(struct dfs_da_args *args);
extern int dfs_dir2_block_removename(struct dfs_da_args *args);
extern int dfs_dir2_block_replace(struct dfs_da_args *args);
extern int dfs_dir2_leaf_to_block(struct dfs_da_args *args,
		struct dfs_buf *lbp, struct dfs_buf *dbp);

/* dfs_dir2_data.c */
#ifdef DEBUG
#define	dfs_dir3_data_check(dp,bp) __dfs_dir3_data_check(dp, bp);
#else
#define	dfs_dir3_data_check(dp,bp)
#endif

extern int __dfs_dir3_data_check(struct dfs_inode *dp, struct dfs_buf *bp);
extern int dfs_dir3_data_read(struct dfs_trans *tp, struct dfs_inode *dp,
		dfs_dablk_t bno, dfs_daddr_t mapped_bno, struct dfs_buf **bpp);
extern int dfs_dir3_data_readahead(struct dfs_trans *tp, struct dfs_inode *dp,
		dfs_dablk_t bno, dfs_daddr_t mapped_bno);

extern struct dfs_dir2_data_free *
dfs_dir2_data_freeinsert(struct dfs_dir2_data_hdr *hdr,
		struct dfs_dir2_data_free *bf, struct dfs_dir2_data_unused *dup,
		int *loghead);
extern int dfs_dir3_data_init(struct dfs_da_args *args, dfs_dir2_db_t blkno,
		struct dfs_buf **bpp);

/* dfs_dir2_leaf.c */
extern int dfs_dir3_leafn_read(struct dfs_trans *tp, struct dfs_inode *dp,
		dfs_dablk_t fbno, dfs_daddr_t mappedbno, struct dfs_buf **bpp);
extern int dfs_dir2_block_to_leaf(struct dfs_da_args *args,
		struct dfs_buf *dbp);
extern int dfs_dir2_leaf_addname(struct dfs_da_args *args);
extern void dfs_dir3_leaf_compact(struct dfs_da_args *args,
		struct dfs_dir3_icleaf_hdr *leafhdr, struct dfs_buf *bp);
extern void dfs_dir3_leaf_compact_x1(struct dfs_dir3_icleaf_hdr *leafhdr,
		struct dfs_dir2_leaf_entry *ents, int *indexp,
		int *lowstalep, int *highstalep, int *lowlogp, int *highlogp);
extern int dfs_dir3_leaf_get_buf(struct dfs_da_args *args, dfs_dir2_db_t bno,
		struct dfs_buf **bpp, __uint16_t magic);
extern void dfs_dir3_leaf_log_ents(struct dfs_trans *tp, struct dfs_inode *dp,
		struct dfs_buf *bp, int first, int last);
extern void dfs_dir3_leaf_log_header(struct dfs_trans *tp, struct dfs_inode *dp,
		struct dfs_buf *bp);
extern int dfs_dir2_leaf_lookup(struct dfs_da_args *args);
extern int dfs_dir2_leaf_removename(struct dfs_da_args *args);
extern int dfs_dir2_leaf_replace(struct dfs_da_args *args);
extern int dfs_dir2_leaf_search_hash(struct dfs_da_args *args,
		struct dfs_buf *lbp);
extern int dfs_dir2_leaf_trim_data(struct dfs_da_args *args,
		struct dfs_buf *lbp, dfs_dir2_db_t db);
extern struct dfs_dir2_leaf_entry *
dfs_dir3_leaf_find_entry(struct dfs_dir3_icleaf_hdr *leafhdr,
		struct dfs_dir2_leaf_entry *ents, int index, int compact,
		int lowstale, int highstale, int *lfloglow, int *lfloghigh);
extern int dfs_dir2_node_to_leaf(struct dfs_da_state *state);

extern bool dfs_dir3_leaf_check_int(struct dfs_mount *mp, struct dfs_inode *dp,
		struct dfs_dir3_icleaf_hdr *hdr, struct dfs_dir2_leaf *leaf);

/* dfs_dir2_node.c */
extern int dfs_dir2_leaf_to_node(struct dfs_da_args *args,
		struct dfs_buf *lbp);
extern dfs_dahash_t dfs_dir2_leafn_lasthash(struct dfs_inode *dp,
		struct dfs_buf *bp, int *count);
extern int dfs_dir2_leafn_lookup_int(struct dfs_buf *bp,
		struct dfs_da_args *args, int *indexp,
		struct dfs_da_state *state);
extern int dfs_dir2_leafn_order(struct dfs_inode *dp, struct dfs_buf *leaf1_bp,
		struct dfs_buf *leaf2_bp);
extern int dfs_dir2_leafn_split(struct dfs_da_state *state,
	struct dfs_da_state_blk *oldblk, struct dfs_da_state_blk *newblk);
extern int dfs_dir2_leafn_toosmall(struct dfs_da_state *state, int *action);
extern void dfs_dir2_leafn_unbalance(struct dfs_da_state *state,
		struct dfs_da_state_blk *drop_blk,
		struct dfs_da_state_blk *save_blk);
extern int dfs_dir2_node_addname(struct dfs_da_args *args);
extern int dfs_dir2_node_lookup(struct dfs_da_args *args);
extern int dfs_dir2_node_removename(struct dfs_da_args *args);
extern int dfs_dir2_node_replace(struct dfs_da_args *args);
extern int dfs_dir2_node_trim_free(struct dfs_da_args *args, dfs_fileoff_t fo,
		int *rvalp);
extern int dfs_dir2_free_read(struct dfs_trans *tp, struct dfs_inode *dp,
		dfs_dablk_t fbno, struct dfs_buf **bpp);

/* dfs_dir2_sf.c */
extern int dfs_dir2_block_sfsize(struct dfs_inode *dp,
		struct dfs_dir2_data_hdr *block, struct dfs_dir2_sf_hdr *sfhp);
extern int dfs_dir2_block_to_sf(struct dfs_da_args *args, struct dfs_buf *bp,
		int size, dfs_dir2_sf_hdr_t *sfhp);
extern int dfs_dir2_sf_addname(struct dfs_da_args *args);
extern int dfs_dir2_sf_create(struct dfs_da_args *args, dfs_ino_t pino);
extern int dfs_dir2_sf_lookup(struct dfs_da_args *args);
extern int dfs_dir2_sf_removename(struct dfs_da_args *args);
extern int dfs_dir2_sf_replace(struct dfs_da_args *args);

/* dfs_dir2_readdir.c */
extern int dfs_readdir(struct dfs_inode *dp, void *dirent, size_t bufsize,
		       dfs_off_t *offset, filldir_t filldir);

#endif /* __DFS_DIR2_PRIV_H__ */
